import mockApi from "@/api/mockApi";
import type {SalaryForm} from '@/types/req/salaryForm'
import type {SalaryQueryForm} from '@/types/req/salaryQueryForm'
import type {Salary} from '@/types/resp/salary'
import type {Response} from '@/types/response'
import type {Result} from '@/types/result'
import type {Page} from "@/types/page";
import dayjs from "dayjs";

export default class salaryApi {
  static salarys: Salary[] = [
    {"id":1,"employeeId":1,"employeeName":"张伟","basicSalary":15000.00,"performanceSalary":5000.00,"bonus":3000.00,"allowance":2000.00,"overtimePay":1200.00,"socialSecurityDeduction":2500.00,"housingFundDeduction":1800.00,"personalIncomeTaxDeduction":1500.00,"otherDeductions":500.00,"grossSalary":26200.00,"netSalary":19900.00,"payDate":dayjs("2024-11-27"),"paymentMethod":10,"bankAccountNumber":"6222021234567890123","createTime":"2024-04-03 22:24:18","modifyTime":"2024-12-18 22:24:18"},
    {"id":2,"employeeId":4,"employeeName":"陈静","basicSalary":18000.00,"performanceSalary":6000.00,"bonus":4000.00,"allowance":2500.00,"overtimePay":1500.00,"socialSecurityDeduction":3000.00,"housingFundDeduction":2000.00,"personalIncomeTaxDeduction":2000.00,"otherDeductions":800.00,"grossSalary":32000.00,"netSalary":24700.00,"payDate":dayjs("2024-09-10"),"paymentMethod":30,"bankAccountNumber":"N/A","createTime":"2024-10-21 22:24:18","modifyTime":"2024-07-12 22:24:18"},
    {"id":3,"employeeId":2,"employeeName":"李娜","basicSalary":12000.00,"performanceSalary":4000.00,"bonus":2000.00,"allowance":1500.00,"overtimePay":1000.00,"socialSecurityDeduction":2000.00,"housingFundDeduction":1500.00,"personalIncomeTaxDeduction":1200.00,"otherDeductions":400.00,"grossSalary":20500.00,"netSalary":15400.00,"payDate":dayjs("2024-05-16"),"paymentMethod":10,"bankAccountNumber":"6222029876543210987","createTime":"2024-12-02 22:24:18","modifyTime":"2024-01-11 22:24:18"},
    {"id":4,"employeeId":3,"employeeName":"王强","basicSalary":20000.00,"performanceSalary":7000.00,"bonus":5000.00,"allowance":3000.00,"overtimePay":2000.00,"socialSecurityDeduction":3500.00,"housingFundDeduction":2500.00,"personalIncomeTaxDeduction":2500.00,"otherDeductions":1000.00,"grossSalary":37500.00,"netSalary":29000.00,"payDate":dayjs("2024-12-14"),"paymentMethod":30,"bankAccountNumber":"N/A","createTime":"2024-03-17 22:24:18","modifyTime":"2024-08-19 22:24:18"},
    {"id":5,"employeeId":1,"employeeName":"张伟","basicSalary":15000.00,"performanceSalary":5000.00,"bonus":3000.00,"allowance":2000.00,"overtimePay":1200.00,"socialSecurityDeduction":2500.00,"housingFundDeduction":1800.00,"personalIncomeTaxDeduction":1500.00,"otherDeductions":500.00,"grossSalary":26200.00,"netSalary":19900.00,"payDate":dayjs("2024-02-27"),"paymentMethod":20,"bankAccountNumber":"zhangwei@alipay.com","createTime":"2024-08-22 22:24:18","modifyTime":"2024-09-26 22:24:18"},
    {"id":6,"employeeId":1,"employeeName":"张伟","basicSalary":15000.00,"performanceSalary":5000.00,"bonus":3000.00,"allowance":2000.00,"overtimePay":1200.00,"socialSecurityDeduction":2500.00,"housingFundDeduction":1800.00,"personalIncomeTaxDeduction":1500.00,"otherDeductions":500.00,"grossSalary":26200.00,"netSalary":19900.00,"payDate":dayjs("2024-09-22"),"paymentMethod":30,"bankAccountNumber":"N/A","createTime":"2024-10-03 22:24:18","modifyTime":"2024-05-28 22:24:18"}
  ]

  static async save (salaryForm: SalaryForm): Promise<Result<void>> {
    console.log('salaryApi save params', salaryForm)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }

  static async find (salaryQueryForm: SalaryQueryForm): Promise<Result<Page<Salary>>> {
    console.log('salaryApi find params', salaryQueryForm)
    const response: Response<Page<object>> = await mockApi.queryPageSuccessfully(salaryApi.salarys)
    return response.data
  }

  static async findById (id: number): Promise<Result<Salary>> {
    console.log('salaryApi findById id', id)
    let target = {}
    for (const a of salaryApi.salarys) {
      if (a.id === id) {
        target = a
      }
    }
    const response: Response<Salary> = await mockApi.operateSuccessfullyWithData(target)
    return response.data
  }

  static async del (id: number): Promise<Result<void>> {
    console.log('salaryApi del id', id)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }
}
